<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<body>
	<div id="app">
	    <button v-for="(item, index) in contents" @click="reddening($event, index)">{{item}}</button>
	</div>
	
	<script type="text/javascript">
		const app = new Vue({
			el: "#app",
			data: {
				preItem: null,
				contents: ["教父","阿甘正传","楚门的世界","盗梦空间"]
			},
			methods: {
				reddening: function(event, index) {
					if(this.preItem != null) {
						this.preItem.style['background-color'] = "white";
					}
					this.preItem = event.target;
					event.target.style.backgroundColor = "red";
				}
			}
		})
	</script>
</body>
</html>